package com.tcm.controller.front;

import com.tcm.entity.resp.R;
import com.tcm.service.BookService;
import com.tcm.utils.AccessTokenUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 学生课程控制器
 * @author Guqier
 * @version 1.0
 * @date 2023/8/16 23:18
 */
@RestController
@RequestMapping("/stu/book")
public class StuBookController {

    @Autowired
    private BookService bookService;

    /**
     * 获取课程列表
     * @param request 请求对象
     * @return 课程列表
     */
    @RequestMapping(value = "/course", method = RequestMethod.GET)
    public R getCourseList(HttpServletRequest request){
        return R.success(bookService.getStuCourse(AccessTokenUtil.getUserId(request)));
    }

    /**
     * 根据课程ID获取卷
     * @param courseId 课程ID
     * @return 卷
     */
    @RequestMapping(value = "/volume", method = RequestMethod.GET)
    public R getVolumeByCourseId(@RequestParam Long courseId){
        return R.success(bookService.getStuVolume(courseId));
    }

    /**
     * 根据卷ID获取章节
     * @param volumeId 卷ID
     * @return 章节
     */
    @RequestMapping(value = "/chapter", method = RequestMethod.GET)
    public R getChapterByCourseId(@RequestParam Long volumeId, HttpServletRequest request){
        return R.success(bookService.getStuChapter(volumeId, AccessTokenUtil.getUserId(request)));
    }

}
